#!/usr/bin/perl -w
use strict;
package MediaWiki::Page;
use MediaWiki::API;
use Scalar::Util qw(blessed);
use MediaWiki::Object;
our @ISA = qw(MediaWiki::Object);

# Parameters
# title: Page to edit
# section: nth section to edit. Use 0 for the top section, 'new' for a new section. Omit if replacing the entire page
# text: New page (or section) content
# token: Edit token
# summary: Edit comment When using section=new, this will be used for the section title
# minor: If set to true, mark the edit as minor
# notminor: If set to true, don't mark the edit as minor, even if you have the "Mark all my edits minor by default" preference enabled
# bot: If set, mark the edit as bot; even if you are using a bot account the edits will not be marked unless you set this flag
# basetimestamp: Timestamp of the last revision, used to detect edit conflicts. Leave unset to ignore conflicts
# starttimestamp: Timestamp when you obtained the edit token. Used to detect page deletions and recreations. Leave unset and use recreate to ignore conflicts
# recreate: If set, suppress errors about the page having been deleted in the meantime and recreate it [1]
# createonly: If set, throw an error if the page already exists [1]
# nocreate: If set, throw a missingtitle error if the page doesn't exist [1]
# watchlist: Specify how the watchlist is affected by this edit, set to one of "watch", "unwatch", "preferences", "nochange":
# watch: add the page to the watchlist
# unwatch: remove the page from the watchlist
# preferences: use the preference settings (Default)
# nochange: don't change the watchlist
# md5: MD5 hash (hex) of the text parameter. If this parameter is set and the hashes don't match, the edit is rejected. This can be used to guard against data corruption
# captchaid: CAPTCHA ID from the previous request
# captchaword: Answer to the CAPTCHA
# undo: Revision ID to undo. Overrides text, prependtext and appendtext
# undoafter: Undo all revisions from undo up to but not including this one. If not set, just undo one revision


sub new {
	my($type,$title) = @_;
	my $self = MediaWiki::Object->new();
	$self->{title} = $title;
	bless($self,$type);
	return $self;
}

sub save {
	my($self,$API) = @_;
	if ( !$API ) {
		$API = $MediaWiki::API::ActiveSession;
		if ( !$API ) {
			print "There is no active MediaWiki session.\n";
			return 0;
		}
	}
	if ( !(Scalar::Util::blessed($API) eq "MediaWiki::API" ) )  {
		print "You must supply a MediaWiki::API object.";
		return 0;
	}
	return $API->writePage($self);
}
1;
